<template>
  <div class="login-container">
    <!-- 顶部装饰条 -->
    <div class="top-decoration"></div>
    
    <!-- 主登录区域 -->
    <div class="login-content">
      <div class="login-header">
        <h1>欢迎回来</h1>
        <p>请登录您的账号</p>
      </div>
      
      <van-form @submit="onSubmit" class="clean-form">
        <van-cell-group :border="false">
          <!-- 手机号输入 -->
          <van-field
            v-model="UserForm.phone"
            left-icon="phone-o"
            placeholder="手机号"
            :rules="loginRules.phone"
            class="clean-field"
          />
          
          <!-- 密码输入 -->
          <van-field
            v-model="UserForm.password"
            left-icon="lock"
            type="password"
            placeholder="请输入密码"
            :rules="loginRules.password"
            class="clean-field"
          />
        </van-cell-group>
        
        <!-- 登录按钮 -->
        <van-button 
          block 
          type="primary" 
          native-type="submit"
          :loading="loading"
          class="submit-btn"
        >
          登录
        </van-button>
        
        <!-- 辅助链接 -->
        <div class="action-links">
          <span @click="onForgotPassword" class="link-text">忘记密码</span>
          <span @click="onRegister" class="link-text">注册账号</span>
        </div>
      </van-form>
      
      <!-- 社交登录 -->
      <div class="social-login">
        <p class="divider">其他登录方式</p>
        <div class="social-icons">
          <van-icon name="wechat" size="24" color="#07C160" />
          <van-icon name="weibo" size="24" color="#E6162D" />
          <van-icon name="qq" size="24" color="#12B7F5" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { showToast } from 'vant';
import { ElMessage } from 'element-plus'

const router = useRouter();
const loading = ref(false);
const UserForm = ref({
  phone: '',
  password: ''
});

// 表单验证规则
const loginRules = {
  phone: [
    { required: true, message: '请输入手机号' },
    { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' }
  ],
  password: [
    { required: true, message: '请输入密码' },
    { pattern: /^.{6,20}$/, message: '密码需6-20位' }
  ]
};

const onSubmit = () => {
  loading.value = true;
  
  // 模拟登录请求
  setTimeout(() => {
    loading.value = false;
    ElMessage.success('登录成功');
    router.push('/home');
  }, 1500);
};

const onForgotPassword = () => {
  showToast('功能开发中');
};

const onRegister = () => {
  router.push('/register');
};
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  background-color: #f8f9fa;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.top-decoration {
  height: 120px;
  background-color: #1989fa;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  border-radius: 0 0 20px 20px;
  z-index: -1;
}

.login-content {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  position: relative;
  width: 100%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-header h1 {
  font-size: 22px;
  color: #333;
  font-weight: 500;
  margin-bottom: 8px;
}

.login-header p {
  font-size: 14px;
  color: #969799;
}

.clean-field {
  padding: 12px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid #ebedf0;
}

:deep(.van-field__left-icon) {
  margin-right: 8px;
  color: #969799;
}

.submit-btn {
  margin-top: 32px;
  height: 44px;
  border-radius: 6px;
  font-size: 16px;
  background-color: #1989fa;
  border: none;
}

.action-links {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  font-size: 14px;
}

.link-text {
  color: #1989fa;
  cursor: pointer;
}

.social-login {
  margin-top: 40px;
  text-align: center;
}

.divider {
  position: relative;
  color: #969799;
  font-size: 14px;
  margin-bottom: 20px;
}

.divider::before,
.divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background-color: #ebedf0;
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

.social-icons {
  display: flex;
  justify-content: center;
  gap: 30px;
}

/* 动画效果 */
.clean-field {
  transition: border-color 0.3s ease;
}

.clean-field:focus-within {
  border-bottom-color: #1989fa;
}

/* 响应式调整 */
@media (max-width: 768px) {
 .login-content {
    max-width: 100%;
  }
}
</style>